package br.com.loja.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import br.com.loja.Bean.LoginBean;
import br.com.loja.Conexao.Conexao;

public class LoginDao {

	Connection con;

	public void inserirLogin(LoginBean login) throws SQLException {
		con = Conexao.getConexao();
		String sql = "INSERT INTO login(nome,usuario,senha) VALUES(?,?,?)";
		PreparedStatement stmt = con.prepareStatement(sql);
		stmt.setString(1, login.getNome());
		stmt.setString(2, login.getUsuario());
		stmt.setString(3, login.getSenha());

		stmt.execute();
		Conexao.closePreparedStatement(stmt);
		Conexao.closeConnection(con);

	}

	public List<LoginBean> verificarLogin() throws SQLException {

		con = Conexao.getConexao();
		String sql = "SELECT * FROM login";
		LoginBean login = new LoginBean();
		List<LoginBean> lista = new ArrayList<LoginBean>();
		Statement stmt = con.prepareStatement(sql);
		ResultSet rs = stmt.executeQuery(sql);

		while (rs.next()) {

			login.setNome(rs.getString("nome"));
			login.setUsuario(rs.getString("usuario"));
			login.setSenha(rs.getString("senha"));
			lista.add(login);
		}
		return lista;
	}
}
